home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1993, Silicon Graphics, Inc.
- * ALL RIGHTS RESERVED
- *
- * Permission to use, copy, modify, and distribute this software for
- * any purpose and without fee is hereby granted, provided that the above
- * copyright notice appear in all copies and that both the copyright notice
- * and this permission notice appear in supporting documentation, and that
- * the name of Silicon Graphics, Inc. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission.
- *
- * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
- * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
- * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
- * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
- * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
- * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
- * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
- * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
- * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
- * (c)(1)(ii) of the Rights in Technical Data and Computer Software
- * clause at DFARS 252.227-7013 and/or in similar or successor
- * clauses in the FAR or the DOD or NASA FAR Supplement.
- * Unpublished-- rights reserved under the copyright laws of the
- * United States. Contractor/manufacturer is Silicon Graphics,
- * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
- *
- * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
- */
- #include <GL/glu.h>
- #include <GL/glx.h>
-
- #include <math.h>
- #include <stdio.h>
-
- #include "Color.h"
- #include "Telescope.h"
-
- inline float radians(float a) {return M_PI * a / 180.0;}
-
- Telescope::Telescope(GLfloat x, GLfloat y)
- {
- xpos = x;
- ypos = y;
-
- divisions = 20;
- radius = .1;
-
- disk = gluNewQuadric();
- cylinder = gluNewQuadric();
- gluQuadricNormals(disk, GLU_FLAT);
- gluQuadricNormals(cylinder, GLU_SMOOTH);
- gluQuadricTexture(disk, GL_TRUE);
- gluQuadricTexture(cylinder, GL_TRUE);
-
- }
-
- Telescope::~Telescope()
- {
- gluDeleteQuadric(disk);
- gluDeleteQuadric(cylinder);
- }
-
- void Telescope::draw_setup(GLfloat fov, GLfloat aspect, int perspective)
- {
- GLfloat near;
-
- /* Worry about the aspect ratio later */
- near = .5 / tan(radians(fov / 2.0));
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- if (perspective) gluPerspective(fov, aspect, near - .01, 10.0);
- else
- fprintf(stderr,
- "Warning: Drawing telescope using orthographic projection.\n");
- gluLookAt(0, 0, -near,
- 0, 0, 1,
- 0, 1, 0);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glTranslatef(xpos, ypos, 0);
- }
-
- void Telescope::draw_fake()
- {
- glBegin(GL_QUADS);
- glColor3f(1, 1, 1);
- glVertex3f(-radius, -radius, .01);
- glVertex3f(radius, -radius, .01);
- glVertex3f(radius, radius, .01);
- glVertex3f(-radius, radius, .01);
- glEnd();
- }
-
- void Telescope::draw_body()
- {
- Color c;
-
- glPushMatrix();
-
- glColor3f(1, 1, 0);
- gluDisk(disk, radius, 1.1 * radius, divisions, 1);
- gluCylinder(cylinder, 1.1 * radius, 1.1 * radius, .1 * radius, divisions, 1);
- glTranslatef(0, 0, .1*radius);
- gluDisk(disk, radius, 1.1 * radius, divisions, 1);
-
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_TEXTURE_2D);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white.c);
- glColor3f(0, 0, 0);
- gluCylinder(cylinder, 1.05 * radius, .95 * radius, .25, divisions, 1);
- glPopAttrib();
-
- /* Would just do this with a push / pop, but that seems to be broken.
- * glGetMaterialfv also seems to be broken, so we can't use that either. */
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black.c);
-
- glTranslatef(0, 0, .25);
- glColor3f(1, 1, 0);
- gluDisk(disk, .95 * radius, 1.05 * radius, divisions, 1);
- gluCylinder(cylinder, 1.05 * radius, 1.05 * radius, .1 * radius,
- divisions, 1);
- glTranslatef(0, 0, .1*radius);
- gluDisk(disk, .95 * radius, 1.05 * radius, divisions, 1);
-
- glPopMatrix();
- }
-
- void Telescope::draw_takedown()
- {
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- }
-
- void Telescope::draw_lens()
- {
- gluDisk(disk, 0, radius, divisions, 1);
- }
-
- void Telescope::set_divisions(int d)
- {
- // Someday we'll put all the quadric stuff in display lists...
- divisions = d;
- }
-
- int Telescope::get_divisions()
- {
- return divisions;
- }
-
- void Telescope::set_radius(GLfloat r)
- {
- // Someday this might have to update some display lists
- radius = r;
- }
-
- GLfloat Telescope::get_radius()
- {
- return radius;
- }
-